import img2pdf
import os

def imageToPdf(absolute_path):
    (path, filename) = os.path.split(absolute_path) #划分文件路径与文件名
    # print(path,filename)

    new_pdf_name = filename.split('.')[0]+".pdf"
    # print(new_file_name)

    # 注意 windows 这里可能会报错，mac与win下的路径不一样 注意这个'/'！！！
    command = "img2pdf " + absolute_path + " -o " + path + '/' +new_pdf_name
    print(command)
    os.system(command)


if __name__ == '__main__':
    imageToPdf("/Users/imastere/Desktop/江财统计学院二学位.png")